﻿using System;

namespace Game1942.Library.Background.Bodies
{
    public class Square : Body
    {
        private readonly int width;
        private readonly int height;

		// Constructors
        public Square (int aWidth, int aHeight)
        {
            width = aWidth;
            height = aHeight;
        }
        
        public override void CreateBodyOf(Element anOwner)
        {
			// Iterate over the length of the sides and add a point over the discrete intervals
            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
					// Check for boundary conditions
                    if( i==0 || j==0 || i==(width-1) || j==(height-1))
                    {
                        bodyList.Add(new ReferencePoint(i,j,anOwner));
                    }
                }
            }
        }

        public override bool BelongsTo(Background map)   //Check if the body belongs to the map
        {
            return (bodyList[0].BelongsTo(map) && bodyList[bodyList.Count - 1].BelongsTo(map));
        }

        public override Point GetBodyDimension()
        {
            return new Point(width,height);
        }
    }
}
